from common.base import Base, By


class RegisterPage(Base):
    # 注册页面地址
    register_url = 'http://172.16.140.55/ecshop/user.php?act=register'

    # 定位到用户名并输入
    def username_ipt(self, username):
        self.find_element((By.ID, 'username')).send_keys(username)

    # 定位到邮箱并输入
    def email_ipt(self, email):
        self.find_element((By.ID, 'email')).send_keys(email)

    # 定位到密码并输入
    def password1_ipt(self, password1):
        self.find_element((By.ID, 'password1')).send_keys(password1)

    # 定位确认密码并输入
    def password2_ipt(self, password2):
        self.find_element((By.ID, 'conform_password')).send_keys(password2)

    # 定位到手机并输入
    def phone_tel_ipt(self, phonenumber):
        self.find_element((By.NAME, 'extend_field5')).send_keys(phonenumber)

    # 定位到办公电话并输入
    def work_tel_ipt(self, worknumber=None):
        self.find_element((By.NAME, 'extend_field3')).send_keys(worknumber)

    # 定位到家庭电话并输入
    def home_tel_ipt(self, homenumber=None):
        self.find_element((By.NAME, 'extend_field4')).send_keys(homenumber)

    # 定位到qq并输入
    def qq_ipt(self, qqnumber=None):
        self.find_element((By.NAME, 'extend_field2')).send_keys(qqnumber)

    # 定位到密码问题下拉框，选中选项
    def questions_select(self, index=0):
        self.select_option((By.TAG_NAME, 'select'), index)

    # 定位到密码问题答案并输入
    def answer_ipt(self, answer=None):
        self.find_element((By.NAME, 'passwd_answer')).send_keys(answer)

    # 定位到立即注册按钮点击
    def register_button(self):
        self.click((By.CLASS_NAME, 'us_Submit_reg'))

    # 定位到提示信息获取文本
    def username_error_tips(self):
        return self.get_element_text((By.XPATH,'/html/body/div[5]/div/div/div/div/p[1]'))

    def email_error_tips(self):
        return self.get_element_text((By.XPATH,'//span[@id="email_notice"]'))

if __name__ == '__main__':
    pass
